package com.sea.supply.controller;


import com.codecrane.core.web.Ajax;
import com.codecrane.core.web.AjaxReturn;
import com.codecrane.core.web.AjaxTableReturn;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sea.product.service.CategoryService;
import com.sea.product.service.ChannelService;
import com.sea.supply.entity.ProduceDetail;
import com.sea.supply.entity.QualityProduceDetail;
import com.sea.supply.entity.QualityProduceType;
import com.sea.supply.service.QualityProduceDetailService;
import com.sea.supply.service.QualityProduceTypeService;
import com.sea.supply.service.QualityReportService;
import com.sea.supply.service.SupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping(value = "/sea/supply/quality/produce/detail")
public class QualityProduceDetailController {

    @Autowired
    private QualityProduceDetailService qualityProduceDetailService;
    /**
     * 分页条件查询
     *
     * @param produceId
     * @return
     */
    @ResponseBody
    @RequestMapping("/findByProduceId")
    public List<QualityProduceDetail> findByProduceId(Integer produceId) {
        return qualityProduceDetailService.findByProduceId(produceId);
    }


    /**
     * 新增
     * @param qualityProduceDetail
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public AjaxReturn save(QualityProduceDetail qualityProduceDetail) {
        AjaxReturn result = Ajax.fail().setMsg("新增失败！");
        try{
            if (null != qualityProduceDetail && qualityProduceDetailService.save(qualityProduceDetail) > 0) {
                result.setOk(true).setMsg("新增成功！");
            }
        }catch (RuntimeException e){
            e.printStackTrace();
            result.setMsg(e.getMessage());
            return result;
        } catch (Exception e){
            e.printStackTrace();
            result.setMsg("系统异常,请联系管理员!");
            return result;
        }
        return result;
    }

    /**
     * 新增
     * @param qualityProduceDetail
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/usave", method = RequestMethod.POST)
    public AjaxReturn usave(QualityProduceDetail qualityProduceDetail) {
        AjaxReturn result = Ajax.fail().setMsg("新增失败！");
        try{
            if (null != qualityProduceDetail && qualityProduceDetailService.save(qualityProduceDetail) > 0) {
                result.setOk(true).setMsg("新增成功！");
            }
        }catch (RuntimeException e){
            e.printStackTrace();
            result.setMsg(e.getMessage());
            return result;
        } catch (Exception e){
            e.printStackTrace();
            result.setMsg("系统异常,请联系管理员!");
            return result;
        }
        return result;
    }

    /**
     * 新增
     * @param qualityProduceDetail
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/updateQualityStatus", method = RequestMethod.POST)
    public AjaxReturn updateQualityStatus(QualityProduceDetail qualityProduceDetail) {
        AjaxReturn result = Ajax.fail().setMsg("生成失败！");
        try{
            if (null != qualityProduceDetail) {
                qualityProduceDetailService.updateQualityStatus(qualityProduceDetail);
                result.setOk(true).setMsg("生成成功！");
            }
        }catch (RuntimeException e){
            e.printStackTrace();
            result.setMsg(e.getMessage());
            return result;
        } catch (Exception e){
            e.printStackTrace();
            result.setMsg("系统异常,请联系管理员!");
            return result;
        }
        return result;
    }


}
